Add a fallback for unconverted backends
authorMatthias Clasen <mclasen@redhat.com>
Mon, 25 Apr 2016 13:07:56 +0000 (09:07 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 28 Apr 2016 03:18:16 +0000 (23:18 -0400)
If the monitor vfuncs are not implemented in a display class,
fall back to providing a single monitor object representing
the entire screen. This is not meant to be 'good enough', it
is just to provide some implementation until all backends
implement the monitor vfuncs. When that is the case, the
fallback should be removed.

gdk/gdkdisplay.c

index d932b50fd9b5aaf089e3c3a7ba2c0902e4cfe61e..f26dd7e9f816bad14db5a83e1dea05ea3c30925a 100644 (file)
@@ -33,6 +33,7 @@
 #include "gdkinternals.h"
 #include "gdkmarshalers.h"
 #include "gdkscreen.h"
+#include "gdkmonitorprivate.h"
 
 #include <math.h>
 #include <glib.h>
@@ -2520,9 +2521,38 @@ gdk_display_get_n_monitors (GdkDisplay *display)
 {
   g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
 
+  if (GDK_DISPLAY_GET_CLASS (display)->get_n_monitors == NULL)
+    return 1;
+
   return GDK_DISPLAY_GET_CLASS (display)->get_n_monitors (display);
 }
 
+static GdkMonitor *
+get_fallback_monitor (GdkDisplay *display)
+{
+  static GdkMonitor *monitor = NULL;
+  GdkScreen *screen;
+
+  if (monitor == NULL)
+    {
+      g_warning ("%s does not implement the monitor vfuncs", G_OBJECT_TYPE_NAME (display));
+      monitor = gdk_monitor_new (display);
+      gdk_monitor_set_manufacturer (monitor, "fallback");
+      gdk_monitor_set_position (monitor, 0, 0);
+      gdk_monitor_set_scale_factor (monitor, 1);
+    }
+
+  screen = gdk_display_get_default_screen (display);
+  gdk_monitor_set_size (monitor,
+                        gdk_screen_get_width (screen),
+                        gdk_screen_get_height (screen));
+  gdk_monitor_set_physical_size (monitor,
+                                 gdk_screen_get_width_mm (screen),
+                                 gdk_screen_get_height_mm (screen));
+
+  return monitor;
+}
+
 /**
  * gdk_display_get_monitor:
  * @display: a #GdkDisplay
@@ -2540,6 +2570,9 @@ gdk_display_get_monitor (GdkDisplay *display,
 {
   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
 
+  if (GDK_DISPLAY_GET_CLASS (display)->get_monitor == NULL)
+    return get_fallback_monitor (display);
+
   return GDK_DISPLAY_GET_CLASS (display)->get_monitor (display, monitor_num);
 }